package com.sy.ecommerce.advice;


import cn.hutool.http.server.HttpServerRequest;
import com.sy.ecommerce.vo.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * <h2>全局异常捕获处理</h2>
 * */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionAdvice {

    public CommonResponse<String> handlerCommerceException(
            HttpServerRequest req, Exception ex
    ) {
        CommonResponse<String> response = new CommonResponse<>(
                -1,"bussiness error"
        );
        response.setData(ex.getMessage());
        log.error("commerce service has error: [{}]",ex.getMessage(),ex);
        return response;
    }
}
